package com.bosicen.crm.service.sysmanage;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import com.bosicen.crm.dao.entity.User;
import com.bosicen.crm.dao.sysmanage.UserDao;
import org.springframework.transaction.annotation.Transactional;

/**
 * 用户信息
 * @author tigerlei
 *
 */
@Service("userService")
public class UserServiceImpl {
	@Autowired
	private UserDao userDao;

	// @Transactional(readOnly = false,propagation=Propagation.REQUIRED,
	// rollbackFor=Exception.class)

	/****
	 * 查询列表
	 * 
	 * @param companyid
	 * @return
	 */
	public List<User> findUserList(int id) {
		List<User> list = null;
		try {
			list = this.userDao.findUserList(id);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return list;
	}

	/***
	 * 新增/修改
	 * 
	 * @param p
	 */
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public boolean saveOrUpdateFunction(User p) {
		try {
			 this.userDao.saveOrUpdate(p);
		} catch (Exception ex) {
			ex.printStackTrace();
			return false;
		}
		return true;
	}

	/****
	 * 按ID查询
	 * 
	 * @param companyid
	 * @return
	 */
	public User findFunctionById(int id) {
		User user = null;
		try {
			user = this.userDao.findUserById(id);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return user;
	}

	/****
	 * 删除 
	 * 
	 * @param p
	 */
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public boolean delFunction(User p) {
		try {
			this.userDao.delete(p);
		} catch (Exception ex) {
			ex.printStackTrace();
			return false;
		}
		return true;
	}
	
	/****
	 * 登录信息查询
	 * @param u
	 * @return
	 */
	public User findUserByLogin(User u){
		return this.userDao.findUserByLogin(u);
	}

}
